package com.rico.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.rico.system.entity.menu.SysMenu;
import com.rico.system.mapper.SysMenuMapper;
import com.rico.system.service.SysMenuService;
import com.rico.system.utils.MenuTreeUtil;
import com.rico.system.vo.MenuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**R®ƒ
 * @author 吴泽胜
 * @FileName SysMenuServiceImpl
 * @date 2021-04-25 5:50 上午
 * @Software: IntelliJ IDEA
 */

@Service
public class SysMenuServiceImpl implements SysMenuService {

    @Autowired
    private SysMenuMapper sysMenuMapper;

    @Override
    public Map<String, Object> selectMenu() {
        Map<String, Object> map = new HashMap<>(16);
        Map<String,Object> home = new HashMap<>(16);
        Map<String,Object> logo = new HashMap<>(16);
        Example example = new Example(SysMenu.class);
        example.createCriteria().andEqualTo("status", true);
        List<SysMenu> menuList = sysMenuMapper.selectByExample(example);
        List<MenuVO> menuInfo = new ArrayList<>();
        for (SysMenu e : menuList) {
            MenuVO menuVO = new MenuVO();
            menuVO.setId(e.getId());
            menuVO.setPid(e.getPid());
            menuVO.setHref(e.getHref());
            menuVO.setTitle(e.getTitle());
            menuVO.setIcon(e.getIcon());
            menuVO.setTarget(e.getTarget());
            menuInfo.add(menuVO);
        }
        map.put("menuInfo", MenuTreeUtil.toTree(menuInfo, 0L));
        home.put("title","首页");
        home.put("href","/page/welcome-1");//控制器路由,自行定义
        logo.put("title","后台管理系统");
        logo.put("image","/static/images/back.jpg");            //静态资源文件路径,可使用默认的logo.png
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("title","首页");
        jsonObject.put("href","/home.html");
        map.put("homeInfo", jsonObject);
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("title","RICO ADMIN");
        jsonObject1.put("image","images/logo.png");
        map.put("logoInfo", jsonObject1);
        return map;
    }
}
